package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.entity.Questionnaire;
import com.wuseguang.springcloud.service.QuestionnaireService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 问卷调查表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-06-02
 */
@RestController
@RequestMapping("/questionnaire")
public class QuestionnaireController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private QuestionnaireService questionnaireServiceImpl;

    /**
     * 添加问卷调查
     * @param request
     * @param questionnaire 问卷调查信息
     * @return
     */
    @RequestMapping("/addQuestionnaire")
    public Result addQuestionnaire(RequestParameterWrapper request, Questionnaire questionnaire){
        logger.info("添加问卷调查");
        //获取学校id
        String schoolId = request.getParam("schoolId");
        //获取老师ID
        String teacherId = request.getParam("teacherId");
        //教师名称
        String teacherName = request.getParam("teacherName");

        questionnaire.setCreatedBy(teacherName);
        questionnaire.setCreatedById(Integer.valueOf(teacherId));
        questionnaire.setSchoolId(Integer.valueOf(schoolId));
        return questionnaireServiceImpl.addQuestionnaire(questionnaire);
    }

    /**
     * 查询问卷调查
     * @param request
     * @return
     */
    @RequestMapping("/findQuestionnaire")
    public Result findQuestionnaire(RequestParameterWrapper request){
        //获取老师ID
        String teacherId = request.getParam("teacherId");
        //获取学校id
        String schoolId = request.getParam("schoolId");
        logger.info("查询问卷调查");
        return questionnaireServiceImpl.findQuestionnaire(teacherId,schoolId);
    }
}

